// shop.js
var app=getApp()
Page({
  data:{
    menuList:[
      {
        text: '综合排序',
        src: '../../images/filterIcon1-active.png',
        className: 'active',
        sort:0
      },
      {
        text: '销量优先',
        src: '',
        className: '',
        sort:1
      }
    ],
    keywords: '',
    isFilter: false
  },
  list: function (type,sort,that){
    var url = app.data.url
    wx.request({
      url: '' + url + '/Shop/MemberBrandSeller/GeList',
      data: { type: type, sort: sort },
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        that.setData({
          list: res.data.Rows
        })

      },
      error: function (res) {
        console.log(res)
      }
    })
  },
  onLoad: function (options) {
    var that = this;
    var type = options.type;
    that.setData({
      type: type
    })
    that.list(type,0,that)
    //资讯详情
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  //clear input
  clearInput: function(e){
    this.keywords = '';
    this.setData({
      keywords: this.keywords
    });
  },
  //实时变化input值
  keywordInput: function(e){
    this.keywords = e.detail.value;
  },
  //点击搜索按钮
  toSearchResultWithKey: function(e){
    wx.navigateTo({
      url: '../search-result/search-result?keywords='+ this.keywords
    });
  },
  /**
   * 点击切换筛选条件
   */
  changeActive: function(e){
   var type=this.data.type;
   this.list(type,e.currentTarget.dataset.sort,this)
    let index = e.currentTarget.dataset.index;
    const length = this.data.menuList.length;
    
    if(index == 2){
      this.isFilter = true;
    }else{
      this.isFilter = false;
    }
    for(let i = 0; i< length;i++){
      if(index == i){
        this.data.menuList[i].className = 'active';
        if(index == 0){
          this.data.menuList[0].src = '../../images/filterIcon1-active.png';
        }else{
          this.data.menuList[0].src = '../../images/filterIcon1.png';
        }
      }else{

        this.data.menuList[i].className = '';
      }
    }
    console.log(this.data.menuList);
    this.setData({
      menuList: this.data.menuList,
      isFilter: this.isFilter
    })
  }
})